<?php

class CController {
	
	protected static $view;

	private		$name = '';

	public function __construct() {
		self::$view = CView::getInstance();
		if(method_exists($this,"_initialize")) {
			$this->_initialize();
		}
	}

	protected function display($file = '') {
		self::$view->display($file);
	}
	
	protected function setTheme($theme = 'default') {
		self::$view->setTheme($theme);
	}
	
	protected function assign($name,$value = '') {
		self::$view->assign($name,$value);
	}

	protected function error() {
		
	}

	protected function success() {
		
	}
	
	protected function redirect($url) {
		redirect($url);
	}

	protected function output($data,$type = '') {
		$type = strtoupper($type);
		if("JSON" == $type) {//输出json
			header('Content-Type:application/json; charset=utf-8');
			exit(json_encode($data));
		} else if("XML" == $type) {//输入xml
			header('Content-Type:text/xml; charset=utf-8');
			exit(xml_encode($data));
		} else if("CSV" == $type) {//导出csv
			$filename	= date('YmdHis') . '.csv';
			header("Content-Type:text/csv");
			header("Content-Disposition:attachment; filename=" . $filename);
			exit(charset("utf-8","gb2312",$data));
		} else {
			header('Content-Type:text/html; charset=utf-8');
            exit($data);  
		}
	}

	

	
}